/**
 * @date 2006-6-8 10:04:52
 *
 */
package org.nanhill.commons.collection;

import java.util.Collection;
import java.util.Iterator;

/**
 * @author alin [xalinx at gmail dot com]
 * 
 */
public class CollectionKit {

	public static boolean isEmpty(Collection<?> coll) {
		return coll == null ? true : coll.size() == 0;
	}

	public static boolean isEmpty(Collection<?>... colls) {
		if (isEmpty(colls)) {
			return true;
		}
		for (Collection<?> coll : colls) {
			if (!isEmpty(coll)) {
				return false;
			}
		}
		return true;
	}

	public static boolean isEquals(Collection<?> src, Collection des) {
		if (null == src || null == des) {
			return true;
		}
		if (0 == src.size() || 0 == des.size()) {
			return true;
		}
		if (src.size() != des.size()) {
			return false;
		}
		Iterator<?> srcIt = src.iterator();
		Iterator<?> desIt = des.iterator();
		for (; srcIt.hasNext();) {
			if (!srcIt.next().equals(desIt.next())) {
				return false;
			}
		}
		return true;
	}

	public static boolean isEquals(Collection<?> des, Object... src) {
		if (null == src || null == des) {
			return true;
		}
		if (0 == src.length || 0 == des.size()) {
			return true;
		}
		if (src.length != des.size()) {
			return false;
		}
		Iterator<?> desIt = des.iterator();
		for (int i = 0; desIt.hasNext(); i++) {
			Object item = desIt.next();
			if (!src[i].equals(item)) {
				return false;
			}
		}
		return true;
	}
}
